package com.niiwoo.civet.mobile.controller.kaola;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.niiwoo.civet.mobile.vo.response.koala.KaoLaLiCaiReceiveVo;
import com.niiwoo.civet.trade.dto.response.kaola.KaoLaLiCaiReceiveDTO;
import com.niiwoo.civet.trade.service.koala.KaoLaLiCaiReceiveFacadeDubboService;
import com.niiwoo.tripod.web.annotation.AuthIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 考拉理财异步通知Controller
 * Created by daizhiyue on 2017/12/25.
 */
@RestController
@Api(tags = "考拉理财异步通知 (戴志越)", description = "/kaolalicai")
@Slf4j
public class KaoLaLiCaiReceiveController {

    @Reference(version = "1.0.0")
    private KaoLaLiCaiReceiveFacadeDubboService kaoLaLiCaiReceiveDubboService;

    @PostMapping(value = "/kaolalicai/{path}")
    @ApiOperation("考拉理财异步通知")
    @AuthIgnore
    public KaoLaLiCaiReceiveVo notify(@PathVariable String path,
                                              @RequestBody JSONObject param,
                                              HttpServletRequest request,
                                              HttpServletResponse response) {
        KaoLaLiCaiReceiveVo baseResponse = new KaoLaLiCaiReceiveVo();
        log.info("KaoLaLiCaiReceiveController request:{}", param.toJSONString());
        KaoLaLiCaiReceiveDTO kaoLaLiCaiReceiveDTO = kaoLaLiCaiReceiveDubboService.processService(param, path);
        log.info("KaoLaLiCaiReceiveController response:{}", JSON.toJSONString(kaoLaLiCaiReceiveDTO));
        BeanUtils.copyProperties(kaoLaLiCaiReceiveDTO, baseResponse);
        return baseResponse;
    }
}
